/**
 * 
 */
package com.easidea.tim.action.system;

import java.util.List;

import com.easidea.tim.action.base.BaseAction;
import com.easidea.tim.entity.saleorder.SaleOrder;
import com.easidea.tim.entity.saleorder.SaleOrderItem;
import com.easidea.tim.service.inventory.StorageService;
import com.easidea.tim.service.saleorder.SaleOrderItemService;
import com.easidea.tim.service.saleorder.SaleOrderService;


/**
 * @author Harrison
 *
 */
public class CompleteSaleOrderAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 445302228663330438L;
	private SaleOrderService saleOrderService;
	private SaleOrderItemService saleOrderItemService;
	private StorageService storageService;

	private String meterstring;
	private	String orderid;
	private String itemid;
	
	
	
	@SuppressWarnings("unchecked")
	public String completeAction() throws Exception{
		SaleOrderItem saleOrderItem = this.saleOrderItemService.get(itemid);
		SaleOrder saleOrder = this.saleOrderService.get(orderid);
		List orderItemlist = this.saleOrderService.getSaleOrderItemsById(new Integer(orderid).longValue());
		String comFlag = "0";
		String isFlag = storageService.isCompleteProduct(saleOrderItem.getProductName(), saleOrderItem.getProductColor(), saleOrderItem.getSaleOrder().getFlowNo(), meterstring);
		if(isFlag.equals("-1")){
			saleOrderItem.setMeterNum(meterstring);
			saleOrderItemService.updateSaleOrderItem(saleOrderItem);	
			//判断该订单是否填充完毕
			for(int i=0;i<orderItemlist.size();i++){
				SaleOrderItem item = (SaleOrderItem)orderItemlist.get(0);
				if(item.getMeterNum().equals("0")){
					comFlag = "1";
					break;
				}
			}
			if(comFlag.equals("0")){
				saleOrder.setStatus(new Integer(2).shortValue());
				saleOrderService.uppdateSaleOrder(saleOrder);
				return "success";
			}	
			return "onesuccess";
		}else{
			return "comfalse";
		}
		
	}
	
	public SaleOrderService getSaleOrderService() {
		return saleOrderService;
	}
	public void setSaleOrderService(SaleOrderService saleOrderService) {
		this.saleOrderService = saleOrderService;
	}


	public String getMeterstring() {
		return meterstring;
	}

	public void setMeterstring(String meterstring) {
		this.meterstring = meterstring;
	}

	public String getOrderid() {
		return orderid;
	}

	public void setOrderid(String orderid) {
		this.orderid = orderid;
	}

	public String getItemid() {
		return itemid;
	}

	public void setItemid(String itemid) {
		this.itemid = itemid;
	}

	public StorageService getStorageService() {
		return storageService;
	}

	public void setStorageService(StorageService storageService) {
		this.storageService = storageService;
	}

	public SaleOrderItemService getSaleOrderItemService() {
		return saleOrderItemService;
	}

	public void setSaleOrderItemService(SaleOrderItemService saleOrderItemService) {
		this.saleOrderItemService = saleOrderItemService;
	}

	
	
	
	
}
